<!--
 * @Author: luoyong/471826078@qq.com
 * @Date: 2020-07-15 10:42:54
 * @LastEditors: 471826078@qq.com
 -->
<template>
  <div class="colSetupBtn">
    <el-dropdown trigger="click">
      <el-button class="commonBut saveBtn funComBut fr">
        列设置
        <i class="el-icon-arrow-down el-icon--right"></i>
      </el-button>
      <el-dropdown-menu
        slot="dropdown"
        style="width: 290px; padding: 20px 20px"
      >
        <div class="export_box_main" v-if="list.length == 22">
          <p class="title" @click="showBase = !showBase">
            <i class="el-icon-caret-bottom"></i>
            <el-checkbox
              :indeterminate="isIndeterminate"
              style="display: inline-block; margin: 0"
              @change="checkAll(1)"
              v-model="isChecked"
              >项目基本信息</el-checkbox
            >
          </p>
          <div :class="showBase ? 'slider ' : 'slider closed '">
            <el-checkbox
              :label="item.label"
              v-model="item.isShow"
              :disabled="item.disabled1"
              v-for="(item, i) in list1"
              :key="item.id"
              @change="check(item, i, 1)"
            ></el-checkbox>
          </div>

          <p class="title" @click="showLink = !showLink">
            <i class="el-icon-caret-bottom"></i
            ><el-checkbox
              :indeterminate="isIndeterminateTel"
              style="display: inline-block; margin: 0"
              @change="checkAll(2)"
              v-model="isCheckedTel"
              >联系方式</el-checkbox
            >
          </p>
          <div :class="showLink ? 'slider1 ' : 'slider1 closed1 '">
            <el-checkbox
              :label="item.label"
              v-model="item.isShow"
              v-for="item in list2"
              :key="item.id"
              @change="check(item, i, 2)"
            ></el-checkbox>
          </div>

          <p class="title">
            <i class="el-icon-caret-bottom"></i
            ><el-checkbox
              :indeterminate="isIndeterminatePro"
              style="display: inline-block; margin: 0"
              @change="checkAll(3)"
              v-model="isCheckedPro"
              >项目数据统计</el-checkbox
            >
          </p>
          <el-checkbox
            :label="item.label"
            v-model="item.isShow"
            v-for="item in list3"
            :key="item.id"
            @change="check(item, i, 3)"
          ></el-checkbox>
        </div>
        <div class="export_box_main" v-if="list.length == 21">
          <p class="title" @click="showBase = !showBase">
            <i class="el-icon-caret-bottom"></i>
            <el-checkbox
              :indeterminate="isIndeterminateInfo"
              style="display: inline-block; margin: 0"
              @change="checkAll(4)"
              v-model="isCheckedInfo"
              >项目基本信息</el-checkbox
            >
          </p>
          <div :class="showBase ? 'slider ' : 'slider closed '">
            <el-checkbox
              :label="item.label"
              v-model="item.isShow"
              :disabled="item.disabled1"
              v-for="item in list4"
              :key="item.id"
              @change="check(item, i, 4)"
            ></el-checkbox>
          </div>

          <p class="title" @click="showLink = !showLink">
            <i class="el-icon-caret-bottom"></i
            ><el-checkbox
              :indeterminate="isIndeterminatePho"
              style="display: inline-block; margin: 0"
              @change="checkAll(5)"
              v-model="isCheckedPho"
              >联系方式</el-checkbox
            >
          </p>
          <div :class="showLink ? 'slider1 ' : 'slider1 closed1 '">
            <el-checkbox
              :label="item.label"
              v-model="item.isShow"
              v-for="item in list5"
              :key="item.id"
              @change="check(item, i, 5)"
            ></el-checkbox>
          </div>
        </div>
        <div
          class="export_box_main"
          v-if="list.length == 13 || list.length == 14"
        >
          <p class="title" @click="showBaseT = !showBaseT">
            <i class="el-icon-caret-bottom"></i
            ><el-checkbox
              :indeterminate="isIndeterminateStatic"
              style="display: inline-block; margin: 0"
              @change="checkAll(6)"
              v-model="isCheckedStatic"
              >待完善项目统计</el-checkbox
            >
          </p>
          <div :class="showBaseT ? 'sliderT' : 'sliderT closedT'">
            <el-checkbox
              :label="item.label"
              v-model="item.isShow"
              :disabled="item.disabled1"
              v-for="item in list"
              :key="item.id"
              @change="check(item, i, 6)"
            ></el-checkbox>
          </div>
        </div>
        <!-- </el-dropdown-item> -->
      </el-dropdown-menu>
    </el-dropdown>
  </div>
</template>

<script>
export default {
  name: 'colSetup',
  props: {
    datas: {
      type: Array,
      default() {
        return []
      },
    },
    more: {
      type: Boolean,
      default: false,
    },
    activeName: {
      type: Number,
    },
  },
  data() {
    return {
      list: this.datas,
      showBase: true,
      showLink: true,
      showBaseT: true,
      //   checkedKeys: [],
      //   selectMenuId: [],
      //   selArr: [],
      //   roleId: "",
      //   checkStrictly: true,
      //   defaultProps: {
      //     children: "children",
      //     label: "label"
      //   }
      checkBox: [], //项目信息
      isIndeterminate: true, //项目信息
      isIndeterminateTel: true, //未落实实名制tab联系方式
      checkBoxTel: [], //未落实实名制tab联系方式
      isIndeterminatePro: false, //未落实实名制tab项目数据统计
      checkBoxPro: [0], //未落实实名制tab项目数据统计
      isIndeterminateInfo: true, //项目信息
      checkBoxInfo: [], //项目信息
      isIndeterminatePho: true, //联系方式
      checkBoxPho: [], //联系方式
      isChecked: false,
      isCheckedTel: false,
      isCheckedPro: true,
      isCheckedInfo: false,
      isCheckedPho: false,
      isCheckedStatic: true,
      isIndeterminateStatic: false,
      checkBoxStatic: [],
    }
  },
  watch: {
    datas: {
      handler(val, old) {
        this.list = val
        this.showBase = true
        this.showLink = true
      },
      deep: true,
      immediate: true,
    },
    activeName: {
      handler(val, old) {
        if (this.list.length == 21) {
          this.check('', '', 4)
          this.check('', '', 5)
        }
        this.$nextTick(function () {
          if (this.list.length == 14) {
            this.check('', '', 6)
          }
        })
      },
      deep: true,
      immediate: true,
    },
  },
  computed: {
    list1: function () {
      let arr = []
      this.datas.forEach((item, index) => {
        if (index < 18 && index != 6) {
          arr.push(item)
        }
      })
      return arr
    },
    list2: function () {
      let arr = []
      this.datas.forEach((item, index) => {
        if (index > 17) {
          arr.push(item)
        }
      })
      return arr
    },
    list3: function () {
      let arr = []
      this.datas.forEach((item, index) => {
        if (index == 6) {
          arr.push(item)
        }
      })
      return arr
    },
    list4: function () {
      let arr = []
      this.datas.forEach((item, index) => {
        if (index < 17) {
          arr.push(item)
        }
      })
      return arr
    },
    list5: function () {
      let arr = []
      this.datas.forEach((item, index) => {
        if (index > 16) {
          arr.push(item)
        }
      })
      return arr
    },
    isCheckAll() {
      if (this.checkBox.length == this.list1.length) {
        return true
      }
      return false
    },
    isCheckAllTel() {
      if (this.checkBoxTel.length == this.list2.length) {
        return true
      }
      return false
    },
    isCheckAllPro() {
      if (this.checkBoxPro.length == this.list3.length) {
        return true
      }
      return false
    },
    isCheckAllInfo() {
      if (this.checkBoxInfo.length == this.list4.length) {
        return true
      }
      return false
    },
    isCheckAllPho() {
      if (this.checkBoxPho.length == this.list5.length) {
        return true
      }
      return false
    },
    isCheckAllStatic() {
      if (this.checkBoxStatic.length == this.list.length) {
        return true
      }
      return false
    },
  },
  methods: {
    check(item, i, type) {
      if (type == 1) {
        if (this.list1.findIndex((target) => target.isShow === false) == -1) {
          this.isIndeterminate = false
          this.isChecked = true
        } else {
          this.isIndeterminate = true
          this.isChecked = false
        }
      } else if (type == 2) {
        if (this.list2.findIndex((target) => target.isShow === false) == -1) {
          this.isIndeterminateTel = false
          this.isCheckedTel = true
        } else {
          if (this.list2.findIndex((target) => target.isShow === true) == -1) {
            this.isIndeterminateTel = false
          } else {
            this.isIndeterminateTel = true
          }
          this.isCheckedTel = false
        }
      } else if (type == 3) {
        if (this.list3.findIndex((target) => target.isShow === false) == -1) {
          this.isIndeterminatePro = false
          this.isCheckedPro = true
          this.checkBoxPro = [0]
        } else {
          if (this.list3.findIndex((target) => target.isShow === true) == -1) {
            this.isIndeterminatePro = false
          } else {
            this.isIndeterminatePro = true
          }
          this.isCheckedPro = false
          this.checkBoxPro = []
        }
      } else if (type == 4) {
        if (this.list4.findIndex((target) => target.isShow === false) == -1) {
          this.isIndeterminateInfo = false
          this.isCheckedInfo = true
          this.checkBoxInfo = []
          for (var i = 0; i < this.list4.length; i++) {
            this.checkBoxInfo.push(i)
          }
        } else {
          this.isIndeterminateInfo = true
          this.isCheckedInfo = false
          this.checkBoxInfo = []
        }
      } else if (type == 5) {
        if (this.list5.findIndex((target) => target.isShow === false) == -1) {
          this.isIndeterminatePho = false
          this.isCheckedPho = true
          this.checkBoxPho = []
          for (var i = 0; i < this.list5.length; i++) {
            this.checkBoxPho.push(i)
          }
        } else {
          if (this.list5.findIndex((target) => target.isShow === true) == -1) {
            this.isIndeterminatePho = false
          } else {
            this.isIndeterminatePho = true
          }
          this.isCheckedPho = false
          this.checkBoxPho = []
        }
      } else if (type == 6) {
        if (this.list.findIndex((target) => target.isShow === false) == -1) {
          this.isIndeterminateStatic = false
          this.isCheckedStatic = true
          this.checkBoxStatic = []
          for (var i = 0; i < this.list.length; i++) {
            this.checkBoxStatic.push(i)
          }
        } else {
          if (this.list.findIndex((target) => target.isShow === true) == -1) {
            this.isIndeterminateStatic = false
          } else {
            this.isIndeterminateStatic = true
          }
          this.isCheckedStatic = false
          this.checkBoxStatic = []
        }
      }
    },
    checkAll(type) {
      if (type == 1) {
        if (this.isCheckAll) {
          for (var i = 0; i < this.list1.length; i++) {
            // 项目信息全不选的时候项目名称、区域、行业默认选中
            if (
              this.list1[i].name == 'projectName' ||
              this.list1[i].name == 'cityName' ||
              this.list1[i].name == 'countyName' ||
              this.list1[i].name == 'townName' ||
              this.list1[i].name == 'industryName'
            ) {
              this.list1[i].isShow = true
            } else {
              this.list1[i].isShow = false
            }
            this.checkBox = []
          }
          this.isIndeterminate = true
        } else {
          for (var i = 0; i < this.list1.length; i++) {
            this.list1[i].isShow = true
            this.checkBox.push(i)
          }
          this.isIndeterminate = false
        }
      } else if (type == 2) {
        if (this.isCheckAllTel) {
          for (var i = 0; i < this.list2.length; i++) {
            this.list2[i].isShow = false
            this.checkBoxTel = []
          }
          // this.isIndeterminateTel = true;
        } else {
          for (var i = 0; i < this.list2.length; i++) {
            this.list2[i].isShow = true
            this.checkBoxTel.push(i)
          }
          this.isIndeterminateTel = false
        }
      } else if (type == 3) {
        if (this.isCheckAllPro) {
          for (var i = 0; i < this.list3.length; i++) {
            this.list3[i].isShow = false
            this.checkBoxPro = []
          }
          // this.isIndeterminatePro = true;
        } else {
          for (var i = 0; i < this.list3.length; i++) {
            this.list3[i].isShow = true
            this.checkBoxPro.push(i)
          }
          this.isIndeterminatePro = false
        }
      } else if (type == 4) {
        if (this.isCheckAllInfo) {
          for (var i = 0; i < this.list4.length; i++) {
            // 项目信息全不选的时候项目名称、区域、行业默认选中
            if (
              this.list4[i].name == 'projectName' ||
              this.list1[i].name == 'cityName' ||
              this.list1[i].name == 'countyName' ||
              this.list1[i].name == 'townName' ||
              this.list4[i].name == 'industryName'
            ) {
              this.list4[i].isShow = true
            } else {
              this.list4[i].isShow = false
            }
            this.checkBoxInfo = []
          }
          this.isIndeterminateInfo = true
        } else {
          for (var i = 0; i < this.list4.length; i++) {
            this.list4[i].isShow = true
            this.checkBoxInfo.push(i)
          }
          this.isIndeterminateInfo = false
        }
      } else if (type == 5) {
        if (this.isCheckAllPho) {
          for (var i = 0; i < this.list5.length; i++) {
            this.list5[i].isShow = false
            this.checkBoxPho = []
          }
          // this.isIndeterminatePho = true;
        } else {
          for (var i = 0; i < this.list5.length; i++) {
            this.list5[i].isShow = true
            this.checkBoxPho.push(i)
          }
          this.isIndeterminatePho = false
        }
      } else if (type == 6) {
        if (this.isCheckAllStatic) {
          for (var i = 0; i < this.list.length; i++) {
            // 项目信息全不选的时候项目名称、区域、行业默认选中
            if (
              this.list[i].name == 'industryName' ||
              this.list[i].name == 'areaName' ||
              this.list[i].name == 'investmentName'
            ) {
              this.list[i].isShow = true
            } else {
              this.list[i].isShow = false
            }
            this.checkBoxStatic = []
          }
          this.isIndeterminateStatic = true
        } else {
          for (var i = 0; i < this.list.length; i++) {
            this.list[i].isShow = true
            this.checkBoxStatic.push(i)
          }
          this.isIndeterminateStatic = false
        }
      }
    },
  },
}
</script>

<style scoped lang="less">
.el-dropdown {
  vertical-align: top;
}
.el-dropdown + .el-dropdown {
  margin-left: 15px;
}
.el-icon-arrow-down {
  font-size: 12px;
}
/deep/ .el-dropdown-menu__item {
  padding: 0 0px;
}

.export_box_main {
  min-height: 100px;
  //   padding: 20px 0;
  min-height: 200px;
  max-height: 600px;
  overflow: auto;
  /deep/.el-checkbox__label {
    &:hover {
      color: #009588 !important;
      text-decoration: underline;
    }
  }
  .title {
    height: 26px;
    line-height: 26px;
    //   padding-left: 30px;
    font-size: 14px;
    color: #666;
    cursor: pointer;
    i {
      width: 13px;
      color: #c0c4cc;
    }
    &:hover {
      background-color: #f5f7fa;
      color: #009588;
      text-decoration: underline;
      i {
        color: #c0c4cc;
      }
    }
  }
  .el-checkbox {
    margin: 0 30px;
    display: block;
    line-height: 26px;
    // padding-left: 24px;
  }
  // .is-checked{
  //   background-color: #f1f2f4;
  // }
  &_title {
    display: flex;
    height: 50px;
    align-items: center;
  }
  .el-checkbox-group {
    margin-left: 50px;
  }
}
.slider {
  overflow-y: hidden;
  max-height: 500px;
  /* 最大高度 */
  height: 442px;
  /*  Webkit内核浏览器：Safari and Chrome*/
  transition-property: all;
  transition-duration: 0.5s;
  transition-timing-function: cubic-bezier(0, 1, 0.5, 1);
  -webkit-transition-property: all;
  -webkit-transition-duration: 0.5s;
  -webkit-transition-timing-function: cubic-bezier(0, 1, 0.5, 1);
  /*  Mozilla内核浏览器：firefox3.5+*/
  -moz-transition-property: all;
  -moz-transition-duration: 0.5s;
  -moz-transition-timing-function: cubic-bezier(0, 1, 0.5, 1);
  /*  Opera*/
  -o-transition-property: all;
  -o-transition-duration: 0.5s;
  -o-transition-timing-function: cubic-bezier(0, 1, 0.5, 1);
  /*  IE9*/
  -ms-transition-property: all;
  -ms-transition-duration: 0.5s;
  -ms-transition-timing-function: cubic-bezier(0, 1, 0.5, 1);
}
.slider1 {
  overflow-y: hidden;
  max-height: 500px;
  /* 最大高度 */
  height: 105px;
  /*  Webkit内核浏览器：Safari and Chrome*/
  transition-property: all;
  transition-duration: 0.5s;
  transition-timing-function: cubic-bezier(0, 1, 0.5, 1);
  -webkit-transition-property: all;
  -webkit-transition-duration: 0.5s;
  -webkit-transition-timing-function: cubic-bezier(0, 1, 0.5, 1);
  /*  Mozilla内核浏览器：firefox3.5+*/
  -moz-transition-property: all;
  -moz-transition-duration: 0.5s;
  -moz-transition-timing-function: cubic-bezier(0, 1, 0.5, 1);
  /*  Opera*/
  -o-transition-property: all;
  -o-transition-duration: 0.5s;
  -o-transition-timing-function: cubic-bezier(0, 1, 0.5, 1);
  /*  IE9*/
  -ms-transition-property: all;
  -ms-transition-duration: 0.5s;
  -ms-transition-timing-function: cubic-bezier(0, 1, 0.5, 1);
}
.sliderT {
  overflow-y: auto;
  max-height: 500px;
  /* 最大高度 */
  height: 382px;
  /*  Webkit内核浏览器：Safari and Chrome*/
  transition-property: all;
  transition-duration: 0.5s;
  transition-timing-function: cubic-bezier(0, 1, 0.5, 1);
  -webkit-transition-property: all;
  -webkit-transition-duration: 0.5s;
  -webkit-transition-timing-function: cubic-bezier(0, 1, 0.5, 1);
  /*  Mozilla内核浏览器：firefox3.5+*/
  -moz-transition-property: all;
  -moz-transition-duration: 0.5s;
  -moz-transition-timing-function: cubic-bezier(0, 1, 0.5, 1);
  /*  Opera*/
  -o-transition-property: all;
  -o-transition-duration: 0.5s;
  -o-transition-timing-function: cubic-bezier(0, 1, 0.5, 1);
  /*  IE9*/
  -ms-transition-property: all;
  -ms-transition-duration: 0.5s;
  -ms-transition-timing-function: cubic-bezier(0, 1, 0.5, 1);
}
.closed,
.closed1,
.closedT {
  height: 0;
  transition-property: all;
  transition-duration: 0.5s;
  transition-timing-function: cubic-bezier(0, 1, 0.5, 1);
  -webkit-transition-property: all;
  -webkit-transition-duration: 0.5s;
  -webkit-transition-timing-function: cubic-bezier(0, 1, 0.5, 1);
}
</style>
